Back to course home
0% completed
Vote For New Content
Amazon Hard Problems
Constrained Subsequence Sum (hard)
Solution: Constrained Subsequence Sum
Number of Valid Subarrays (hard)
Solution: Number of Valid Subarrays
Count Vowels Permutation (hard)
Solution: Count Vowels Permutation
Concatenated Words (hard)
Solution: Concatenated Words
Minimum Replacements to Sort the Array (hard)
Solution: Minimum Replacements to Sort the Array
Count All Valid Pickup and Delivery Options (hard)
Solution: Count All Valid Pickup and Delivery Options
Length of the Longest Valid Substring (hard)
Solution: Length of the Longest Valid Substring
Count Array Pairs Divisible by K (hard)
Solution: Count Array Pairs Divisible by K
Word Ladder (hard)
Solution: Word Ladder
Path with Maximum Sum (hard)
Solution: Path with Maximum Sum
Split Linked List in Parts (medium)
Problem Statement
Given a head of the singly linked list and integer k, split the list into k consecutive parts and return them.
The length of each part should not differ more than 1, and it may lead to some parts being null.
The order of parts should be the same as given in the input list, and parts in the start should have a size greater than or equal to the parts in the end.
Examples
Example 1:
- Input: head =
[1, 2, 3, 4, 5, 6, 7], k =3 - Expected Output:
[[1, 2, 3], [4, 5], [6, 7]] - Justification: The list of 8 elements is divided into 3 parts. The first part has 3 elements and the last two parts have 2 elements, distributing the nodes as evenly as possible.
Example 2:
- Input: head =
[1, 2, 3], k =4 - Expected Output:
[[1], [2], [3], []] - Justification: The list of 3 elements is divided into 4 parts, resulting in the first three parts having one element each and the last one part being empty, as there are fewer nodes than parts.
Example 3:
- Input: head =
[1, 2, 3, 4, 5, 6, 7], k =2 - Expected Output:
[[1, 2, 3, 4], [5, 6, 7]] - Justification: The list of 7 elements is divided into 2 parts. The first part contains 4 elements and the second part contains 3 elements, making the parts as equal in size as possible.
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Maximize Distance to Closest Person
Solution: Split Linked List in Parts
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself